#ifndef __ZONE_SIT_MGR_H__
#define __ZONE_SIT_MGR_H__

#include <vector>
#include <time.h>
#include <string>
#include "dbmgr.h"
#include "common_def.h"
#include "proto_29000_zone_sit_info.h"
#include "proto_29002_zone_state.h"


class GlobalServer;

struct ZoneSitData
{
	ZoneSitData()
	{
		zone = 0;
		sit = 0;
		playerCnt = 0;
		updateTime = 0;
		robot = 0;
		strPwd = "";
		nSetPwd = 0;
		nSetPwdTime = 0;
	}

	~ZoneSitData()
	{

	}

	int zone;
	int sit;
	int playerCnt;
	int updateTime;
	int robot;
	int nSetPwd;
	int nSetPwdTime;
	string strPwd;
};

class ZoneSitMgr
{
public:
	ZoneSitMgr();

	~ZoneSitMgr();

private:
	ZoneSitMgr(const ZoneSitMgr &rhs);

	ZoneSitMgr &operator=(const ZoneSitMgr &rhs);

public:
	void init(base::FileConfig &confMgr, base::Logger *pLogger, GlobalServer *pServer);

	int getZoneSitInfo(int nZone, int nTimeStamp, std::vector<proto29zone::ProtoSitInfo> &vetSitinfo);
	
	void updateZoneSitInfo(int nZone, int nSit, int nPlayerCnt);

	void reload();

	void getZoneState(int nRoomtype, std::vector<proto29zone::ProtoZoneState> &vecZoneState);

	void getZoneState(int nZone, proto29zone::ProtoZoneState &zoneState);

	void saveAll2Cache();

	void save2Cache(int nZone, int nSit, int nNum, int nUpdated, int robot);

	void save2Cache(ZoneSitData &data);

	void loadFromCache();

	int checkRobotZone(const int &nZone);

	void initZoneData(const int &nZone, const int &nTotal);

	bool isRobotZone(const int &nZone, const int &nSit);

	bool initRobotZoneRule(const int &nZone, const int &nRuleId);

	bool passwdValid(const int &nZone, const int &nSit, const string &strPwd);

	string getZoneSitPwd(const int &nZone, const int &nSit);

	//判断房间座位是否已经满人
	bool isRoomFull(const int &nZone, const int &nSit);

private:
	DBMgr *m_pDbMgr;
	base::Logger *m_pRollLog;
	GlobalServer *m_pServer;
	std::map<int, map<int, ZoneSitData> > m_mapZone2SitInfo; //key是区id，value是座位信息数组
	std::map<int, int> m_mapZone2Num; //key是区id，value是区人数
	map< int, vector<int> > m_mapZoneRobot; //机器人房间号
	map<int, int> m_mapRobotRule;//当前机器人规则

};
#endif

